package atm;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 存款界面
 */
public class SavePanel extends JPanel implements ActionListener {
    private ATMFrame atmFrame;
    private JTextField blanceTextField = new JTextField();
    private ImageIcon savepane = new ImageIcon("Tu/buttonSave.jpg");
    private JLabel accountLabel = new JLabel("存款");
    private JTextField accountField = new JTextField();
    private Font font = new Font("黑体", Font.BOLD, 30);

    private JButton loginBtn = new JButton(savepane);


    public SavePanel(ATMFrame atmFrame) {
        this.atmFrame=atmFrame;
        this.setLayout(null);
        accountLabel.setBounds(300, 200, 120, 50);
        accountLabel.setFont(font);
        accountField.setBounds(400, 200, 250, 50);    //输入空格
        accountLabel.setFont(font);
        accountField.setText("请输入存款的金额：");

        loginBtn.setBounds(700, 350, 140, 50);    //按钮
        loginBtn.addActionListener(this);


        this.add(accountLabel);
        this.add(accountField);   //输入空格
        this.add(loginBtn);      //按钮


        this.setOpaque(false);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource()==loginBtn){
            User user = atmFrame.getLoginUser();
            try{
                user.setBlance(user.getBlance() + Double.parseDouble( accountField .getText()));
            }catch (NumberFormatException e1){
                JOptionPane.showMessageDialog(this,"必须输入数字");
                return;
            }
            atmFrame.switchPanel("menu");
        }

    }
}